package com.toobigtofail.enitities
{
	import Box2D.Collision.Shapes.b2MassData;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.Joints.b2RevoluteJointDef;
	import Box2D.Dynamics.b2Body;
	
	import com.toobigtofail.shapes.IShape;
	import com.toobigtofail.shapes.Octagon;
	import com.toobigtofail.shapes.Wedge;
	
	import fabulaexmachina.box2fp.Box2DEntity;
	import fabulaexmachina.box2fp.Box2DWorld;
	import fabulaexmachina.box2fp.graphics.SuperGraphiclist;
	
	import net.flashpunk.FP;
	import net.flashpunk.Graphic;
	import net.flashpunk.Sfx;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.PreRotation;
	
	public class BatShit extends Box2DEntity
	{
		//sfx embed
		[Embed(source="/assets/sfx/shitFore.mp3")]   private const SHIT_SFX:Class;
		
		[Embed(source="/assets/gfx/batshit.png")] private static const BATSHIT_PNG:Class;
		public static const TYPE:String ="shit";
		
		private var _shape:IShape;
		
		private var _speed:Number = 1;
		
		private var _initOptions:Object;
		
		public var imgShit:PreRotation = new PreRotation(BATSHIT_PNG);
		
		public function BatShit(x:Number=0,y:Number=0)
		{
			var shitSfx:Sfx = new Sfx(SHIT_SFX);
			shitSfx.play(0.3);
			_shape = new Octagon(x,y,0.1,b2Body.b2_dynamicBody)
			_initOptions = {}
			super(_shape.X, _shape.Y, _shape.Width, _shape.Height, _shape.b2Type);
			
			type = BatShit.TYPE;
			
			gravity = new b2Vec2(0,30);
			
			this.addGraphic(imgShit);
			imgShit.x = (imgShit.width/-2);
			imgShit.y = (imgShit.height/-2);
			imgShit.centerOrigin();;
			
			
		}
		
		override public function added():void
		{
			super.added();
			/*var spikeJointDef:b2RevoluteJointDef = new b2RevoluteJointDef;
			spikeJointDef.Initialize(this.body, _initOptions.cavern.body, this.body.GetWorldCenter());*/
			//body.SetLinearVelocity(new b2Vec2(0, -_speed));
			//angleRads = _initOptions.angleRads;
			
		}
		override public function buildShapes(friction:Number, 
											 density:Number, restitution:Number,
											 group:int, category:int, collmask:int):void { 
			_shape.buildShape(body);
			body.SetType(_shape.b2Type);
		}
		
		public function set speed(s:Number):void
		{
			_speed = s;
			if (body) gravity = new b2Vec2(0,_speed);
		}
		public function get speed():Number { return _speed; }
		
		override public function update():void
		{
			super.update();
			if(this.body.GetWorldCenter().y > FP.height)
			{
				this.remove();
			}
		}
	}
}